/************************************************
 * Copyright (c) 2007 ~ 2009, 
 * All rights reserved.
 * Version   : 1.0
 * Author    : lengsh@gmail.com 
 * Date      : 2009.2.1
 ***********************************************/

#ifndef   __PANDA_MEMCACHE_H___
#define   __PANDA_MEMCACHE_H___


#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <syslog.h>
#include <signal.h>
#include <unistd.h>
#include <map>
#include <pthread.h>
#include "MemConnection.h"
#include "ICache.h"
using namespace std;
using namespace panda;

typedef struct MemConn{
	MemConnection *pCon;

#ifdef _PTHREAD_SAFE
	pthread_mutex_t lock;
#endif

} MemConn;

class MemCache : public ICache {
	protected:
        int m_iPartition;
		map < int, MemConn * > m_Conn_Map;
    protected:
		void _Lock(int idx);
		void _UnLock(int idx);
	public:
	MemCache():m_iPartition(0) {  }
	virtual ~MemCache();
	virtual bool Initialize(const char *conf) ;
        virtual int ResetCacheStatus(const char *ip, int port);
	virtual int Set(const char *data, unsigned dlen); //, char **rval, unsigned &rlen);
	virtual int Set(int ihash, GHashTable *kv);
	virtual int Get(const char *data, unsigned dlen, char **buf,unsigned &wsize, unsigned &vlen) ;
	virtual int Incr(const char *data, unsigned dlen, char **rval,unsigned &wsize, unsigned &rlen);
	virtual int Decr(const char *data, unsigned dlen, char **rval,unsigned &wsize, unsigned &rlen);
	virtual int Delete(const char *data, unsigned dlen); //, char **rval,unsigned &wsize, unsigned &rlen);

};


#endif  // __PANDA_MEMCACHE_H___

